/*
* Copyright @ 2014 com.iflysse.trains
* manger_v2.0 上午10:48:55
* All right reserved.
*
*/
package com.iflysse.service;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import com.iflysse.dao.ColumnInfoDao;
import com.iflysse.pojo.ColumnInfo;
import com.iflysse.utils.MySessionFactory;
import com.iflysse.utils.PagerBean;

/**
 * @desc: manger_v2.0
 * @author: wql
 * @createTime: 2014年11月20日 上午10:48:55
 * @history:
 * @version: v1.0
 */
public class ColumnInfoService {

	/**
	*
	* @author: wql
	* @createTime: 2014年11月20日 上午10:51:44
	* @history:
	* @param pager
	* @return PagerBean<ColumnInfo>
	*/
	private SqlSessionFactory sf;

	public ColumnInfoService() {
		sf = MySessionFactory.getSessionFactory();
	}
	
	public PagerBean<ColumnInfo> findColumnPager(PagerBean<ColumnInfo> pager) {
		SqlSession session = sf.openSession();
		try {
			ColumnInfoDao dao = (ColumnInfoDao) session
					.getMapper(ColumnInfoDao.class);
			List<ColumnInfo> ColumnList = dao.findColumnPager(pager);
			long total = dao.findColumnTotal(pager);
			pager.setRows(ColumnList);
			pager.setTotal(total);
		} finally {
			session.close();
		}
		return pager;
	}
	
	public List<ColumnInfo> findAllColumn() {
		SqlSession session = sf.openSession();
		List<ColumnInfo> columnList;
		try {
			ColumnInfoDao dao = (ColumnInfoDao) session
					.getMapper(ColumnInfoDao.class);
			columnList = dao.findAllColumn();
		} finally {
			session.close();
		}
		return columnList;
	}

	/**
	*
	* @author: wql
	* @createTime: 2014年11月20日 下午2:57:37
	* @history:
	* @param column void
	*/
	public void updatetcolumn(ColumnInfo column) {
		SqlSession session =sf.openSession();
		ColumnInfoDao dao=(ColumnInfoDao)session.getMapper(ColumnInfoDao.class);
		ColumnInfo co=column;		
		dao.updateColumn(co);
		session.commit();
		session.close();		
	}

	/**
	*
	* @author: wql
	* @createTime: 2014年11月20日 下午2:58:42
	* @history:
	* @param column void
	*/
	public void insertcolumn(ColumnInfo column) {
		SqlSession session =sf.openSession();
		ColumnInfoDao dao=session.getMapper(ColumnInfoDao.class);
		ColumnInfo co=column;
		dao.insertColumn(co);
		session.commit();
		session.close();		
	}

	/**
	*
	* @author: wql
	* @createTime: 2014年11月20日 下午3:00:19
	* @history:
	* @param columnid
	* @return ColumnInfo
	*/
	public ColumnInfo findColumnById(int columnid) {
		SqlSession session = sf.openSession();
		ColumnInfo column=null;
		try {
			ColumnInfoDao dao = (ColumnInfoDao) session.getMapper(ColumnInfoDao.class);
			column = dao.findColumnById(columnid);
		} finally {
			session.close();
		}
		return column;
	}

	/**
	*
	* @author: wql
	* @createTime: 2014年11月20日 下午3:02:52
	* @history:
	* @param columnid void
	*/
	public void delColumnById(int columnid) {
		SqlSession session = sf.openSession();
		try {
			ColumnInfoDao dao = (ColumnInfoDao) session
					.getMapper(ColumnInfoDao.class);
			dao.delById(columnid);
			session.commit();
		} finally {
			session.close();
		}
		
	}

	/**
	*
	* @author: wql
	* @createTime: 2014年11月20日 下午4:19:35
	* @history:
	* @param pager
	* @return PagerBean<ColumnInfo>
	*/
	public List<ColumnInfo> findColumnByName(String name) {
		SqlSession session = sf.openSession();
		List<ColumnInfo> column=null;
		try {
			ColumnInfoDao dao = (ColumnInfoDao) session.getMapper(ColumnInfoDao.class);
			column = dao.findColumnByName(name);
		} finally {
			session.close();
		}
		return column;
	}
    
	public List<ColumnInfo> findChildrensColumnById(int id) {
		SqlSession session=null;
		List<ColumnInfo> infos=null;
		try{
			session=sf.openSession();
			ColumnInfoDao dao=session.getMapper(ColumnInfoDao.class);
			infos=dao.findChildrensColumnById(id);
		}finally{
			session.close();
		}
		return infos;
	}
	
	
}
